package com.food.controller;

import com.food.common.Result;
import com.food.model.UserFoodPreference;
import com.food.service.FoodPreferenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "食谱收藏管理")
@RestController
@RequestMapping("/api/food/preference")
public class FoodPreferenceController {

    @Autowired
    private FoodPreferenceService preferenceService;

    @ApiOperation("收藏食物")
    @PostMapping("/{foodId}")
    public Result<?> addPreference(
            @RequestParam Integer userId,
            @PathVariable Integer foodId) {
        return preferenceService.addPreference(userId, foodId);
    }

    @ApiOperation("取消收藏")
    @DeleteMapping("/{foodId}")
    public Result<?> removePreference(
            @RequestParam Integer userId,
            @PathVariable Integer foodId) {
        return preferenceService.removePreference(userId, foodId);
    }

    @ApiOperation("获取收藏列表")
    @GetMapping
    public Result<List<UserFoodPreference>> getPreferences(
            @RequestParam Integer userId) {
        return Result.success(preferenceService.getPreferences(userId));
    }
} 